﻿using SIG.Model.Store;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace SIG.Model.Mapping
{
    public class GoodsMap: EntityTypeConfiguration<Goods>
    {
        public GoodsMap()
        {
            this.HasKey(p => p.Id);

            this.Property(p => p.Id)
                .HasColumnName("Id").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(p => p.Name).IsRequired().HasMaxLength(150);          
            this.Property(p => p.Description).IsOptional();
            this.Property(p => p.FullDescription).IsOptional();

            this.Property(p => p.Price).IsRequired().HasPrecision(18, 2); ;   
            this.Property(p => p.Thumbnail).HasMaxLength(150);
            this.Property(p => p.CategoryId).IsRequired();

            this.Property(p => p.CreatedDate).IsOptional().HasColumnType("datetime");
            this.Property(p => p.CreatedBy).HasMaxLength(50);
            this.Property(p => p.UpdatedDate).IsOptional().HasColumnType("datetime");
            this.Property(p => p.UpdatedBy).IsOptional().HasMaxLength(50);


            this.HasRequired(p => p.GoodsCategory)
              .WithMany(h => h.Goods)
              .HasForeignKey(p => p.CategoryId)
              .WillCascadeOnDelete(true);
            

            this.ToTable("GoodsSet");
        }
    }
}
